<?php

namespace App\Admin\Extensions\Form;

use Encore\Admin\Form\Field;

/**
 * Created by PhpStorm.
 * User: frowhy
 * Date: 2017/7/21
 * Time: 下午12:02
 */
class WangEditor extends Field
{
    protected $view = 'admin.form.editor';

    protected static $css = [
        '/vendor/laravel-admin/wangEditor-3.1.1/release/wangEditor.min.css',
    ];

    protected static $js = [
        '/vendor/laravel-admin/wangEditor-3.1.1/release/wangEditor.min.js',
    ];

    public function render()
    {
        $name = $this->formatName($this->column);

        $this->script = <<<EOT

var E = window.wangEditor
var editor = new E('#{$this->id}');
editor.customConfig.debug = false
editor.customConfig.uploadFileName = 'wang-editor-image-file'
editor.customConfig.uploadImgServer = '/admin/upload/uploadImg'
editor.customConfig.uploadImgMaxSize = 5 * 1024 * 1024
editor.customConfig.customAlert = function (info) {
    alert('自定义提示：' + info)
}
editor.customConfig.uploadImgParams = {
    _token: LA.token
}
editor.customConfig.zIndex = 0

editor.customConfig.onchange = function (html) {
    $('input[name=\'$name\']').val(html);
}
editor.customConfig.debug = true

editor.create()

EOT;
        return parent::render();
    }
}